package Cain.moveMenu 
{
	import flash.events.Event;
	/**
	 * 選項陣列
	 * @author cain in liontravel 2010
	 */
	public dynamic class ItemAce extends Array
	{
		static public const ALL_LOAD:String = "ItemAce_ALL_LOAD";
		
		private var ww:Number;
		private var hh:Number;
		private var id:int;
		/**
		 * Item陣列
		 * @param	_ww 寬
		 * @param	_hh 高
		 */
		public function ItemAce(_ww:Number,_hh:Number) 
		{
			id = -1;
			ww = _ww;
			hh = _hh;
		}
		/**
		 * 新增Item
		 * @param	_path 圖路徑
		 * @param	_link 連結網址
		 * @param	_windows 開啟視窗
		 * @param	_color 背景色
		 * @return id
		 */
		public function addItem(_path:String,_link:String = "",_windows:String = "_blank",_color:uint = 0):int
		{
			id++;
			var _item:Item = new Item(ww, hh, id, _color);
			_item.pcxPath = _path;
			_item.itemlink(_link, _windows);
			push(_item);
			return id;
		}
		/**
		 * 用id取回Item
		 * @param	_id 
		 * @return 
		 */
		public function getItem(_id:int):Item
		{
			var _item:Item = null
			for each (_item in this) 
			{
				if (_item.id == _id) 
				{
					break;
				}
			}
			return _item;
		}
		/**
		 * 開始串流載入圖
		 * @param	_loading_class 載入動畫class
		 */
		public function allLoad(_loading_class:String = ""):void 
		{
			load_class = _loading_class;
			load(0,load_class);
		}
		private var now_id:int;
		private var load_class:String
		private function load(_id:int,_class:String):void
		{
			var _item:Item = Item(this[_id]);
			_item.load("", _class);
			_item.addEventListener(Event.COMPLETE, on_itemCOMPLETE);
		}
		
		private function on_itemCOMPLETE(e:Event):void 
		{
			e.currentTarget.removeEventListener(Event.COMPLETE, on_itemCOMPLETE);
			now_id++;
			if (length>now_id)
			{
				load(now_id, load_class);
			}else 
			{
				Item(this[0]).parent.dispatchEvent(new Event(ItemAce.ALL_LOAD));
			}
		}
	}

}